home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Frameworks / TransSkel 3.18 / Demos / C Demos / MultiSkel / MultiSkel.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-04  |  4.4 KB  |  215 lines  |  [TEXT/KAHL]

  1. /*
  2.  * Should add menu hook routine to dim Close item when no windows are active.
  3.  *
  4.  * MultiSkel - TransSkel multiple-window demonstration main module
  5.  *
  6.  * This module performs setup and termination operations, installs
  7.  * the window and menu handlers, and processes menu item selections.
  8.  *
  9.  * There are four window handlers in this demonstration.  The code
  10.  * for each handler is in its own module.
  11.  *
  12.  * Help Window        Scrollable non-editable text window
  13.  * Edit Window        Non-scrollable editable text window
  14.  * Zoom Window        Non-manipulable graphics display window
  15.  * Region Window    Manipulable graphics display window
  16.  *
  17.  * 21 Apr 88 Paul DuBois
  18.  * 29 Jan 89 Version 1.01
  19.  * - Conversion for TransSkel 2.0.
  20.  * 12 Jan 91 Version 1.02
  21.  * - Conversion for TransSkel 3.00.
  22.  * 05 Jun 93 Version 1.03
  23.  * - Conversion for THINK C 6.0.
  24.  * 15 Feb 94
  25.  * - Numerous minor revisions.
  26.  * 21 Feb 94
  27.  * - Updated for TransSkel 3.11.
  28.  * 04 Nov 94
  29.  * - Updated for TransSkel 3.18 (Support for Universal headers, PowerPC,
  30.  * Metrowerks).
  31.  */
  32.  
  33. # include    "TransSkel.h"
  34.  
  35. # include    "MultiSkel.h"
  36.  
  37.  
  38. /* File menu item numbers */
  39.  
  40. typedef enum {
  41.     open = 1,
  42.     close,
  43.     /* --- */
  44.     quit = 4
  45. } fileItems;
  46.  
  47.  
  48. WindowPtr    helpWind;
  49. WindowPtr    editWind;
  50. WindowPtr    zoomWind;
  51. WindowPtr    rgnWind;
  52.  
  53.  
  54. /*
  55.  * Menu handles.  There isn't any Apple menu here, since TransSkel will
  56.  * be told to handle it itself.
  57.  */
  58.  
  59. static MenuHandle    fileMenu;
  60. MenuHandle            editMenu;
  61.  
  62. static RgnHandle    oldClip;
  63.  
  64.  
  65. /*
  66.  * Miscellaneous routines
  67.  * These take care of drawing the grow box and the line along
  68.  * the right edge of the window, and of setting and resetting the clip
  69.  * region to disallow drawing in that right edge by the other drawing
  70.  * routines.
  71.  */
  72.  
  73.  
  74. void
  75. DrawGrowBox (WindowPtr wind)
  76. {
  77. Rect        r;
  78. RgnHandle    oldClip;
  79.  
  80.     r = wind->portRect;
  81.     r.left = r.right - 15;        /* draw only along right edge */
  82.     oldClip = NewRgn ();
  83.     GetClip (oldClip);
  84.     ClipRect (&r);
  85.     DrawGrowIcon (wind);
  86.     SetClip (oldClip);
  87.     DisposeRgn (oldClip);
  88. }
  89.  
  90.  
  91. void
  92. SetWindClip (WindowPtr wind)
  93. {
  94. Rect        r;
  95.  
  96.     r = wind->portRect;
  97.     r.right -= 15;        /* don't draw along right edge */
  98.     oldClip = NewRgn ();
  99.     GetClip (oldClip);
  100.     ClipRect (&r);
  101. }
  102.  
  103.  
  104. void
  105. ResetWindClip (void)
  106. {
  107.     SetClip (oldClip);
  108.     DisposeRgn (oldClip);
  109. }
  110.  
  111.  
  112. /*
  113.  * Show a window if it's not visible.  Select the window FIRST, then
  114.  * show it, so that it comes up in front.  Otherwise it will be drawn
  115.  * in back then brought to the front, which is ugly.
  116.  *
  117.  * The test for visibility must be done carefully:  the window manager
  118.  * stores 255 and 0 for true and false, not real boolean values.
  119.  */
  120.  
  121. static void
  122. MyShowWindow (WindowPtr wind)
  123. {
  124.  
  125.     if (((WindowPeek) wind)->visible == false)
  126.     {
  127.         SelectWindow (wind);
  128.         ShowWindow (wind);
  129.     }
  130. }
  131.  
  132.  
  133. /*
  134.  * Handle selection of About MultiSkel... item from Apple menu
  135.  */
  136.  
  137. static pascal void
  138. DoAppleMenu (short item)
  139. {
  140.     (void) SkelAlert (aboutAlrtRes, SkelDlogFilter (nil, true),
  141.                                         skelPositionOnParentDevice);
  142.     SkelRmveDlogFilter ();
  143. }
  144.  
  145.  
  146. /*
  147.  * Process selection from File menu.
  148.  *
  149.  * Open        Make all four windows visible
  150.  * Close    Hide the frontmost window.  If it belongs to a desk accessory,
  151.  *            close the accessory.
  152.  * Quit        Request a halt by calling SkelHalt().  This makes SkelMain
  153.  *            return.
  154.  */
  155.  
  156. static pascal void
  157. DoFileMenu (short item)
  158. {
  159.     switch (item)
  160.     {
  161.         case open:
  162.             MyShowWindow (rgnWind);
  163.             MyShowWindow (zoomWind);
  164.             MyShowWindow (editWind);
  165.             MyShowWindow (helpWind);
  166.             break;
  167.  
  168.         case close:
  169.             SkelClose (FrontWindow ());
  170.             break;
  171.  
  172.         case quit:
  173.             SkelStopEventLoop ();        /* request halt */
  174.             break;
  175.     }
  176. }
  177.  
  178.  
  179. /*
  180.  * Initialize menus.  Tell TransSkel to process the Apple menu automatically,
  181.  * and associate the proper procedures with the File and Edit menus.
  182.  * The Edit menu is enabled only when the Edit is frontmost.
  183.  *
  184.  * \311 = ellipsis character
  185.  */
  186.  
  187. static void
  188. SetUpMenus (void)
  189. {
  190.     SkelApple ((StringPtr) "\pAbout MultiSkel\311", DoAppleMenu);
  191.     fileMenu = GetMenu (fileMenuRes);
  192.     (void) SkelMenu (fileMenu, DoFileMenu, nil, false, false);
  193.     editMenu = GetMenu (editMenuRes);
  194.     (void) SkelMenu (editMenu, EditWindEditMenu, nil, false, true);
  195. }
  196.  
  197.  
  198. int
  199. main (void)
  200. {
  201. long    f, b;
  202.  
  203.     SkelInit ((SkelInitParamsPtr) nil);
  204.     SkelGetWaitTimes (&f, &b);
  205.     b = f;
  206.     SkelSetWaitTimes (f, b);
  207.     SetUpMenus ();            /* install menu handlers */
  208.     RgnWindInit ();            /* install window handlers  */
  209.     ZoomWindInit ();
  210.     EditWindInit ();
  211.     HelpWindInit ();
  212.     SkelEventLoop ();        /* process events */
  213.     SkelCleanup ();            /* throw away windows and menus */
  214. }
  215.